﻿//-------------------------------------------------------------------------
///-----------------JsonMsgMgr---------------------------------------------
///-----------------Json消息解析器-----------------------------------------
///-----------------2022/3/28---by mky.蒙克雨------------------------------
//-------------------------------------------------------------------------
#pragma once

//-------------------------------------------------------------------------
#ifndef _CLASS_JSONMSGMGR_H
#define _CLASS_JSONMSGMGR_H

//-------------------------------------------------------------------------------------
#include "../Singleton.hpp"
#include <json/json.h>
#include <mutex>
//-------------------------------------------------------------------------------------
namespace mv {

	//-------------------------------------------------------------------------------------
	class JsonMsgMgr :public Singleton<JsonMsgMgr> {
		DECL_CLASSNAME(JsonMsgMgr)
		DECL_SINGLETON(JsonMsgMgr)
	public:
		~JsonMsgMgr();
		//-------------------------------------------------------------------------------------
		std::string GetStringByJson(Json::Value& root);

		//-------------------------------------------------------------------------------------
		Json::Value GetJsonByString(const std::string& rawJson);
		//-------------------------------------------------------------------------------------
		std::string GetJsonMsgBody(Json::Value& root, const Json::Value& params);
		std::string GetJsonMsgBody(Json::Value& root);
		std::string GetJsonMsg(const std::string& message); 
		std::string GetJsonMsg(const std::string& method, const int& code, const std::string& message, bool modle=false);
		std::string GetJsonMsg(const std::string& method,const int& code, const std::string& message, const std::string& requestId,bool modle = false);
		Json::Value GetJsonMsgHead(
			const std::string& method,
			const int& code,
			const std::string& message,
			const std::string& requestId = "",
			const std::string& version = "",
			const std::string& clientId = "",
			const std::string& deviceName = "");
		std::string GetJsonMsg(Json::Value& task, const std::string& code, const std::string& message);
		//-------------------------------------------------------------------------------------
	private:
		std::mutex m_mutex;

		//-------------------------------------------------------------------------------------
	};

	//-------------------------------------------------------------------------------------
}

//-------------------------------------------------------------------------
#endif //!_CLASS_MQTTSESSION_H
